const express = require('express');
const router = express.Router();
const jwt = require('jsonwebtoken');
const secretKey = 'role_id'
var {usersModel,cityModel,addressModel}=require('../model/daichunyuan')

// 用户登录
router.post('/userLogin', async(req, res)=>{
    const body=req.body
    const code=body.code
    const token = jwt.sign({ code }, secretKey, { expiresIn: '1h' });
    try {
      await usersModel.create({
        userName:body.data,
        userUrl: body.userurl,
        userAuth: body.userAuth
      });
      res.send({ code: 200, msg: '登录成功', token });
    } catch (error) {
      console.error(error);
      res.status(500).send({ code: 500, msg: '登录失败' });
    }
});


module.exports = router;